home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / interToUI.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.7 KB  |  134 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date:  1 December 1996
  22. //<doc>
  23. //<name interToUI>
  24. //<owner "Alias|Wavefront Unsupported">
  25. //
  26. //<synopsis>
  27. //        string interToUI(string $interCapName)
  28. //
  29. //<description>
  30. //      Takes a string in interCaps form,
  31. //      and returns a "UI" string.  Allows
  32. //      things that are called something like
  33. //      graphEditor to be shown to the
  34. //      user as "Graph Editor"
  35. //
  36. //<flags>
  37. //        string    $interCapName    Name to convert, assumed to be in interCaps.
  38. //
  39. //<returns>
  40. //      string : Converted name
  41. //
  42. //<examples>
  43. //  interToUI( "graphEditor" );
  44. //  // Result : Graph Editor //
  45. //  interToUI( "heffalump" );
  46. //  // Result : Heffalump //
  47. //  interToUI( "AndWoozles" );
  48. //  // Result : And Woozles //
  49. //
  50. //</doc>
  51. //
  52. global proc string interToUI( string $input )
  53. {
  54.  
  55.     string $retval = "";
  56.     int $stringSize = size( $input );
  57.     
  58.     if (0 < $stringSize) {
  59.         string $character = substring( $input, 1, 1 );
  60.         string $upperChar = toupper( $character );
  61.         $retval = ( $retval + $upperChar );
  62.  
  63.         int $parenLevel = 0;
  64.         int $capitalizeNext = false;
  65.         string $prevChar = $character;
  66.  
  67.         for( $i=2; $i <= $stringSize; $i++ ) {
  68.             $character = substring( $input, $i, $i );
  69.             $upperChar = toupper( $character );
  70.  
  71.             // Capitalize this character if the previous was a "."
  72.             //
  73.             if( $capitalizeNext ) {
  74.                 $character = $upperChar;
  75.             }
  76.  
  77.             // Do not add spaces before numbers or brackets/parens
  78.             // or else "myMultiAttr[16]" will come out as 
  79.             // "My Multi Attr [ 1 6 ]"
  80.             //
  81.             int $isOpenParen =  size( match( "\\[", $character ) ) ||
  82.                                 size( match( "\\(", $character ) );
  83.             int $isCloseParen=     size( match( "\\]", $character ) ) ||
  84.                                 size( match( "\\)", $character ) );
  85.  
  86.             int $isPeriod    =  size( match( "\\.", $character ) );
  87.  
  88.             // Increment the level of nested parens
  89.             //
  90.             if( $isOpenParen ) {
  91.                 $parenLevel++;
  92.             } 
  93.  
  94.             // Take "." to mean a new phrase starts and we
  95.             // need a capital letter.
  96.             //
  97.             if( $isPeriod ) {
  98.                 $capitalizeNext = true;
  99.             }
  100.  
  101.             // If the character is already capitalized, then
  102.             // insert a space before putting the character
  103.             // back into the string
  104.             //
  105.             if( ($character==$upperChar) && !$isPeriod && ($parenLevel==0) )
  106.             {
  107.                 // The only exception is if we're beginning a new
  108.                 // phrase. "T.Tx" should remain "T.Tx" not "T. Tx"
  109.                 //
  110.                 // Also, don't separate groups of caps.  
  111.                 // "colorRGB" should appear as "Color RGB"
  112.                 // not "Color R G B".
  113.                 //
  114.                 if( !$capitalizeNext 
  115.                 &&( $prevChar != toupper($prevChar) ) ) 
  116.                 {
  117.                     $retval = ( $retval + " " );                    
  118.                 }
  119.                 $capitalizeNext = false;
  120.             }
  121.             
  122.             // Decrement the level of nested parens
  123.             //
  124.             if( $isCloseParen ) {
  125.                 $parenLevel--;
  126.             }
  127.  
  128.             $retval = ( $retval + $character );
  129.             $prevChar = $character;
  130.         }
  131.     }
  132.     return $retval;
  133. }
  134.